package com.fhz.mvvm.viewmodel

import androidx.lifecycle.LiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.fhz.loginmvvm.callback.ApiResponse
import com.fhz.mvvm.entity.User
import com.fhz.mvvm.entity.UserEntity
import com.fhz.mvvm.repository.UserRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import dagger.hilt.android.scopes.ViewModelScoped
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import javax.inject.Inject

/**
 * 时间:2023/3/28
 * @author Mr.Feng
 * 简述: TODO
 */
@HiltViewModel
class UserViewModel @Inject constructor(private val repository: UserRepository) : ViewModel() {


    fun login(name:String,pwd:String) : LiveData<ApiResponse<UserEntity>> {
        return repository.login(name,pwd)
    }

    fun insertUser(user: User){
        viewModelScope.launch {
            repository.insertUser(user)
        }
    }

}